import Vue from 'vue'
import VueRouter from 'vue-router'

import Layout from '@/layout'
import NotFound from '@/layout/components/NotFound'

Vue.use(VueRouter)

export const routes = [
  {
    path: '/redirect',
    component: Layout,
    children: [
      {
        path: '/redirect/:path(.*)',
        component: () => import('@/pages/redirect/index'),
      },
    ],
  },
  {
    path: '/404',
    name: 'NotFound',
    component: NotFound,
  },
  {
    path: '/login',
    meta: { title: '登录' },
    component: () => import('@/pages/login/index'),
  },
  {
    path: '/',
    component: Layout,
    redirect: '/home',
    children: [
      {
        path: 'home',
        component: () => import('@/pages/home/index'),
        name: 'Home',
        meta: { title: '校园安全数据一览' },
      },
    ],
  },
  // 五困生
  {
    path: '',
    component: Layout,
    redirect: '/fiveHard',
    children: [
      {
        path: 'fiveHard',
        component: () => import('@/pages/fiveHard/index'),
        name: 'FiveHard',
        meta: { title: '五困生统计' },
      },
      {
        path: 'collegeMsg',
        component: () => import('@/pages/fiveHard/collegeMsg'),
        name: 'CollegeMsg',
        meta: { title: '五困生学院' },
      },
      {
        path: 'gradeMsg',
        component: () => import('@/pages/fiveHard/gradeMsg'),
        name: 'GradeMsg',
        meta: { title: '五困生年级' },
      },
      // 全校维度-五困生统计-4班级，学生维度-五困生列表
      {
        path: 'classesListMsg',
        component: () => import('@/pages/fiveHard/classesListMsg'),
        name: 'classesListMsg',
        meta: { title: '五困生' },
      },
      {
        path: 'fiveHardDetail',
        component: () => import('@/pages/fiveHard/fiveHardDetail'),
        name: 'FiveHardDetail',
        meta: { title: '五困生详情' },
      },
      {
        path: 'talkRecord',
        component: () => import('@/pages/fiveHard/talkRecord'),
        name: 'TalkRecord',
        meta: { title: '谈心谈话记录' },
      },
      {
        path: 'instructorMsg',
        component: () => import('@/pages/fiveHard/instructorMsg'),
        name: 'InstructorMsg',
        meta: { title: '辅导员' },
      },
    ],
  },
  // 辅导员
  {
    path: '',
    component: Layout,
    redirect: '/counsellor',
    children: [
      {
        path: 'counsellor',
        component: () => import('@/pages/counsellor/index'),
        name: 'Counsellor',
        meta: { title: '全校辅导员工作进度管理' },
      },
      {
        path: 'collegeRate',
        component: () => import('@/pages/counsellor/collegeRate'),
        name: 'CollegeRate',
        meta: { title: '学院辅导员工作进度管理' },
      },
      {
        path: 'counsellorRate',
        component: () => import('@/pages/counsellor/counsellorRate'),
        name: 'CounsellorRate',
        meta: { title: '工作进度' },
      },
      {
        path: 'noHandleTasks',
        component: () => import('@/pages/counsellor/noHandleTasks'),
        name: 'NoHandleTasks',
        meta: { title: '未处理任务详情' },
      },
    ],
  },

  // 学生请假统计
  {
    path: '',
    component: Layout,
    redirect: '/leaveStatistics',
    children: [
      {
        path: 'leaveStatistics',
        component: () => import('@/pages/leaveStatistics/index'),
        name: 'LeaveStatistics',
        meta: { title: '学生请假统计' },
      },
    ],
  },

  // 预警学生
  {
    path: '',
    component: Layout,
    redirect: '/warningStu',
    children: [
      {
        path: 'warningStu',
        component: () => import('@/pages/warningStu/index'),
        name: 'WarningStu',
        meta: { title: '预警学生' },
      },
      {
        path: '/warningList',
        component: () => import('@/pages/warningStu/warningList'),
        name: 'warningList',
        meta: { title: '学院' },
      },
    ],
  },
  // 搜索
  {
    path: '',
    component: Layout,
    redirect: '/search',
    children: [
      {
        path: 'search',
        component: () => import('@/pages/search/index'),
        name: 'Search',
        meta: { title: '搜索' },
      },
    ],
  },
]

const createRouter = () =>
  new VueRouter({
    mode: 'hash',
    scrollBehavior: () => ({ y: 0 }),
    routes,
  })

const router = createRouter()

export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher
}

export default router
